

import 'package:flutter/material.dart';

class YkMovingWidget extends StatefulWidget {

  final Widget removableWidget;
  double left;
  double top;

  double minX;
  double minY;
  double maxX;
  double maxY;

  YkMovingWidget({super.key, required this.removableWidget, required this.left, required this.top, required this.minX, required this.minY, required this.maxX, required this.maxY});


  @override
  State<YkMovingWidget> createState() => _YkMovingWidgetState();
}

class _YkMovingWidgetState extends State<YkMovingWidget> {

  @override
  Widget build(BuildContext context) {
    return Positioned(
      left: widget.left,
      top: widget.top,
      child: GestureDetector(
          onPanUpdate: (details) {
            final x = widget.left + details.delta.dx;
            final y = widget.top + details.delta.dy;
            if (x > widget.minX && x < widget.maxX && y > widget.minY && y < widget.maxY) {
              setState(() {
                widget.left = x;
                widget.top = y;
              });
            }
          },
          child: widget.removableWidget),
    );
  }
}
